package com.oak.broke.model.vip.base;

import com.oak.broke.constant.ResponseConstant;
import lombok.Data;

/**
 * @author tanghan
 * @Description 统一返回
 * @date 2023/04/12/ 19:05:00
 */
@Data
public class ResponseMessage<T> {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 无参构造函数
     */
    public ResponseMessage() {
    }

    /**
     * 全参构造函数
     *
     * @param code 返回转台吗
     * @param msg  提示信息
     * @param data 返回数据
     */
    public ResponseMessage(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 响应成功
     *
     * @param msg  提示信息
     * @param data 返回数据
     * @param <T>  泛型
     * @return
     */
    public static <T> ResponseMessage success(String msg, T data) {
        return new ResponseMessage<>(ResponseConstant.SUCCESS_CODE, msg, data);
    }

    /**
     * 响应成功
     *
     * @return
     */
    public static ResponseMessage success() {
        return new ResponseMessage<>(ResponseConstant.SUCCESS_CODE, ResponseConstant.SUCCESS_MSG, null);
    }

    /**
     * 响应成功
     *
     * @param data 返回数据
     * @param <T>  泛型
     * @return
     */
    public static <T> ResponseMessage<T> success(T data) {
        return new ResponseMessage<>(ResponseConstant.SUCCESS_CODE, ResponseConstant.SUCCESS_MSG, data);
    }

    /**
     * 响应失败
     *
     * @param code 状态码
     * @param msg  提示信息
     * @return
     */
    public static ResponseMessage fail(Integer code, String msg) {
        return new ResponseMessage<>(code, msg, null);
    }
}
